import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { SecTimerViewData } from "../../../common/cd/SecTimerViewData";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
type int = number;
//class SecTimerView
    
    export  class SecTimerView extends GTextFiled
    {
        constructor()
        {
            super();
            return;
        }

        public setLeftTime(arg1: int, arg2: Boolean=true): void
        {
            if (arg1 < 0) 
            {
                arg1 = 0;
            }
            if (!this._secTimerViewData) 
            {
                this._secTimerViewData = new SecTimerViewData();
            }
            this._secTimerViewData.setLeftTime(arg1, arg2);
            this._secTimerViewData.caller = this.update;
            if (this._timeOutCallBack != null) 
            {
                this._secTimerViewData.timeOutCaller = this._timeOutCallBack;
            }
            this.update();
            return;
        }

        public setLeftColor(arg1: int, arg2: string): void
        {
            this._cLeftTime = arg1;
            this._cColor = arg2;
            return;
        }

        public getLeftTime(): int
        {
            if (this._secTimerViewData) 
            {
                return this._secTimerViewData.leftTime;
            }
            return 0;
        }

        public stop(): void
        {
            if (this._secTimerViewData) 
            {
                this._secTimerViewData.stop();
            }
            return;
        }

        /* internal  */update(): void
        {
            var loc1=null;
            var loc2;
            var loc3=((loc2 = this)._updateCount + 1);
            loc2._updateCount = loc3;
            if (this._colorChange && this._colorChange.length > 0) 
            {
                this._curColorIndex = this._updateCount % this._colorChange.length;
                this._curColor = this._colorChange[this._curColorIndex];
            }
            if (this.getLeftTime() <= this._cLeftTime) 
            {
                this._curColor = this._cColor;
            }
            if (this._curColor) 
            {
                this.htmlText = HTMLUtil.addColor(this._secTimerViewData.parse(this._strParse), this._curColor);
            }
            else 
            {
                loc1 = this._secTimerViewData.parse(this._strParse);
                this.htmlText = loc1;
            }
            this.dispatchEvent(new DataEvent(EventName.SecViewTimeChange, this._secTimerViewData.leftTime));
            return;
        }

        public setParse(arg1: string): void
        {
            this._strParse = arg1;
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            if (this._secTimerViewData) 
            {
                this._secTimerViewData.dispose();
            }
            this._secTimerViewData = null;
            this._colorChange = null;
            this._timeOutCallBack = null;
            this._updateCount = 0;
            this._curColorIndex = 0;
            this._curColor = null;
            defaultTextFormat = GlobalStyle.textFormat6;
            this.styleSheet = null;
            this.text = "";
            this.htmlText = "";
            this.setTextFormat(this.defaultTextFormat);
            super.dispose(arg1);
            return;
        }

        public get secTimerViewData(): SecTimerViewData
        {
            return this._secTimerViewData;
        }

        public set timeOutHandler(arg1: Function)
        {
            this._timeOutCallBack = arg1;
            if (this._secTimerViewData) 
            {
                this._secTimerViewData.timeOutCaller = this._timeOutCallBack;
            }
            return;
        }

        public set colorChange(arg1: Array<any>)
        {
            this._colorChange = arg1;
            return;
        }

        public get running(): Boolean
        {
            if (this._secTimerViewData) 
            {
                return this._secTimerViewData.running;
            }
            return false;
        }

        public get parse(): string
        {
            return this._strParse;
        }

        /* internal */ /* var */_secTimerViewData: SecTimerViewData;

        /* internal */ /* var */_strParse: string="mm: ss";

        /* internal */ /* var */_timeOutCallBack: Function;

        /* internal */ /* var */_colorChange: Array<any>;

        /* internal */ /* var */_cLeftTime: int;

        /* internal */ /* var */_cColor: string;

        /* internal */ /* var */_updateCount: int;

        /* internal */ /* var */_curColorIndex: int;

        /* internal */ /* var */_curColor: string;
    }
